import Vue from "vue";
import Router from "vue-router";
import MainComps from "components/main/mainComps";
import FooterTab from "components/tab/footerTab";
import LoadMore from "components/loadMore/loadMore";
import Home from "pages/home/home";
import Card from "pages/card/card";
import Indent from "pages/indent/indent";
import Mine from "pages/mine/mine";
import InviteVip from "pages/inviteVip/inviteVip";
import VipDetail from "pages/vipDetail/vipDetail"
import Order from "pages/order/order";
import OrderComplete from "pages/orderComplete/orderComplete";
import Apply from "pages/apply/apply";
import Landing from "pages/landing/landing";
import activityJd from "pages/activity/activityJd"
import Ranking from "pages/ranking/ranking"
import Loans from "pages/loans/loans"
import DownLoadApp from "pages/downLoadApp/downLoadApp"

Vue.component('loadmore', LoadMore)
Vue.use(Router);

// Router.prototype.goBack = function () {
//     this.isBack = true;
//     window.history.go(-1);
// };

let router = new Router({
  // mode: 'history',
  routes: [
    {
      path: '/',
      redirect: '/loans'
    },
    {
      path: '/home',
      component: MainComps,
      children: [
        {
          path: '',
          name: 'home',
          components: {
            body: Home,
            footer: FooterTab
          },
          meta: {
            title: '首页'
          }
        }
      ]
    },
    {
      path: '/card',
      component: MainComps,
      children: [
        {
          path: '',
          name: 'card',
          components: {
            body: Card,
            footer: FooterTab
          },
          meta: {
            title: '办卡'
          }
        }
      ]
    },
    {
      path: '/loans',
      component: MainComps,
      children: [
        {
          path: '',
          name: 'loans',
          components: {
            body: Loans,
            footer: FooterTab
          },
          meta: {
            title: '我要贷款'
          }
        }
      ]
    },
    // {
    //   path: '/indent',
    //   component: MainComps,
    //   children: [
    //     {
    //       path: '',
    //       name: 'indent',
    //       components: {
    //         body: Indent,
    //         footer: FooterTab
    //       },
    //       meta: {
    //         title: '订单'
    //       }
    //     }
    //   ]
    // },
    {
      path: '/mine',
      component: MainComps,
      children: [
        {
          path: '',
          name: 'mine',
          components: {
            body: Mine,
            footer: FooterTab
          },
          meta: {
            title: '我的'
          }
        }
      ]
    },
    {
      path: '/inviteVip',
      component: MainComps,
      children: [
        {
          path: '',
          name: 'invite-vip',
          components: {
            body: InviteVip,
          },
          meta: {
            title: '邀请会员'
          }
        }
      ]
    },
    {
      path: '/vipDetail',
      component: MainComps,
      children: [
        {
          path: '',
          name: 'invite-detail',
          components: {
            body: VipDetail,
          },
          meta: {
            title: '会员权益'
          }
        }
      ]
    },
    {
      path: '/order',
      component: MainComps,
      children: [
        {
          path: '',
          name: 'order',
          components: {
            body: Order,
          },
          meta: {
            title: '支付'
          }
        }
      ]
    },
    {
      path: '/orderComplete',
      component: MainComps,
      children: [
        {
          path: '',
          name: 'order-complete',
          components: {
            body: OrderComplete,
          },
          meta: {
            title: '支付完成页'
          }
        }
      ]
    },
    {
      path: '/apply',
      component: MainComps,
      children: [
        {
          path: '',
          name: 'apply',
          components: {
            body: Apply,
          },
          meta: {
            title: '申请人信息'
          }
        }
      ]
    },
    {
      path: '/landing',
      component: MainComps,
      children: [
        {
          path: '',
          name: 'landing',
          components: {
            body: Landing,
          },
          meta: {
            title: '注册生财有道'
          }
        }
      ]
    },
    {
      path: '/activityJd',
      component: MainComps,
      children: [
        {
          path: '',
          name: 'activity-jd',
          components: {
            body: activityJd,
          },
          meta: {
            title: '活动详情'
          }
        }
      ]
    },
    {
      path: '/ranking',
      component: MainComps,
      children: [
        {
          path: '',
          name: 'ranking',
          components: {
            body: Ranking,
          },
          meta: {
            title: '排行榜'
          }
        }
      ]
    },
    {
      path: '/downLoadApp',
      component: MainComps,
      children: [
        {
          path: '',
          name: 'down-load-app',
          components: {
            body: DownLoadApp,
          },
          meta: {
            title: '下载APP'
          }
        }
      ]
    },

  ]
})

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title;
  } else {
    document.title = to.query.title;
  }
  next();
})

export default router

